#include <stdlib.h>
#include <netinet/in.h>


enum Endian {
	Big,
	Little
};

typedef struct {
	u_int8_t *buffer;
	size_t offset;
	size_t size;
} Writer;

typedef struct {
	u_int8_t *buffer;
	size_t offset;
	size_t size;
} Reader;


int writebytes(Writer *writer, u_int8_t *data, size_t count);

int writebyte(Writer *writer, u_int8_t data);

int writeshort(Writer *writer, enum Endian endian, u_int16_t data);

int writetriad(Writer *writer, enum Endian endian, u_int32_t data);

int writeint(Writer *writer, enum Endian endian, u_int32_t data);

int writevarint(Writer *writer, u_int32_t data);

int writelong(Writer *writer, enum Endian endian, u_int64_t data);

int writevarlong(Writer *writer, u_int64_t data);

int writeaddressv4(Writer *writer, struct sockaddr_in address);

int writeaddressv4(Writer *writer, struct sockaddr_in address);


int readbytes(Reader *reader, u_int8_t *data, size_t count);

int readbyte(Reader *reader, u_int8_t *data);

int readshort(Reader *reader, u_int16_t *data, enum Endian endian);

int readtriad(Reader *reader, u_int32_t *data, enum Endian endian);

int readint(Reader *reader, u_int32_t *data, enum Endian endian);

int readvarint(Reader *reader, u_int32_t *data);

int readlong(Reader *reader, u_int64_t *data, enum Endian endian);

int readvarlong(Reader *reader, u_int64_t *data);

int readaddressv4(Reader *reader, struct sockaddr_in *addrt);
